﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>产品列表</title>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <link href="/style/admin/style/adminStyle.css" rel="stylesheet" type="text/css" />
        <script src="/style/admin/js/jquery.js"></script>
        <script src="/style/admin/js/public.js"></script>
        <style>
            ul, li { 
                float: left;
            }
            .active,.disabled{
                width:30px;
                height:30px;
                line-height: 30px;
                background: white;
            }
        </style>
    </head>
    <body>
        <div class="wrap">
            <div class="page-title">
                <span class="modular fl"><i></i><em>产品列表</em></span>
                <span class="modular fr"><a href="/admin/types/create" class="pt-link-btn">+添加商品</a></span>
            </div>
            <div class="operate">
                <form action="/admin/types/res" method="post"> 
                    {{ csrf_field() }}
                    <input type="text" name="name" class="textBox length-long" placeholder="输入产品名称..."/>
                    <input type="submit" value="查询" class="tdBtn"/>
                </form>
            </div>
            <table class="list-style Interlaced">
                <tr>
                    <th>ID编号</th>
                    <th>产品</th>
                    <th>名称</th>
                    <th>市场价</th>
                    <th>会员价</th>
                    <th>库存</th>
                    <th>精品</th>
                    <th>新品</th>
                    <th>热销</th>
                    <th>操作</th>
                </tr>
                @foreach($data as $value)
                <tr>
                    <td>
                        <span>
                            <input type="checkbox" value="{{$value->id}}" class="middle children-checkbox ckb"/>
                            <i>{{$value->id}}</i>
                        </span>
                    </td>
                    <td class="center pic-area"><img src="{{$value->img}}" class="thumbnail"/></td>
                    <td class="td-name">
                        <span class="ellipsis td-name block" style="text-align: center;">{{$value->title}}</span>
                    </td>
                    <td class="center">
                        <span>
                            <i>￥</i>
                            <em>{{$value->m_price}}</em>
                        </span>
                    </td>
                    <td class="center">
                        <span>
                            <i>￥</i>
                            <em>{{$value->price}}</em>
                        </span>
                    </td>
                    <td class="center">
                        <span>
                            <em>{{$value->num}}</em>
                            <i>件</i>
                        </span>
                    </td>
                    @if($value->is_best==1)
                    <td class="center"><img onclick='EditStatus_best(this,{{$value->id}}, 0, "is_best");' src="/style/admin/images/yes.gif"/></td>
                    @else
                    <td class="center"><img onclick='EditStatus_best(this,{{$value->id}}, 1, "is_best");' src="/style/admin/images/no.gif"/></td>
                    @endif

                    @if($value->is_news==1)
                    <td class="center"><img onclick='EditStatus_news(this,{{$value->id}}, 0, "is_news");' src="/style/admin/images/yes.gif"/></td>
                    @else
                    <td class="center"><img onclick='EditStatus_news(this,{{$value->id}}, 1, "is_news");' src="/style/admin/images/no.gif"/></td>
                    @endif

                    @if($value->is_host==1)
                    <td class="center"><img onclick='EditStatus_host(this,{{$value->id}}, 0, "is_host");' src="/style/admin/images/yes.gif"/></td>
                    @else
                    <td class="center"><img onclick='EditStatus_host(this,{{$value->id}}, 1, "is_host");' src="/style/admin/images/no.gif"/></td>
                    @endif
                    <td class="center">
                        <a href="javascript::;" title="查看" target="_blank"><img src="/style/admin/images/icon_view.gif"/></a>
                        <a href="/admin/types/{{$value->id}}/edit" title="编辑"><img src="/style/admin/images/icon_edit.gif"/></a>
                        <a title="删除" href="javascript::;" onclick="del({{$value->id}});"><img src="/style/admin/images/icon_drop.gif"/></a>
                    </td>
                </tr> 
                @endforeach
            </table>
            <!-- BatchOperation -->
            <div style="overflow:hidden;">
                <!-- Operation -->
                <div class="BatchOperation fl">
                    <input type="checkbox" id="del" onclick="SelectAll()"/>
                    <label for="del" class="btnStyle middle">全选</label>
                    <input type="button" value="批量删除" onclick="all_Del()" class="btnStyle"/>
                </div>
                <!-- turn page -->
                <div class="turnPage center fr">
                   {{$data->links()}}
                </div>
            </div>
        </div>
        <script>
            //更改is_best状态
            function EditStatus_best(obj, id, value){
            $.post("/admin/types/ExitStatus", {"id":id, "_token":"{{csrf_token()}}", "_method":"post", 'is_best':value}, function(data){ 
            if (value == 0){
                 if (data == 1){ 
                       $(obj).parent().html('<img onclick=EditStatus_best(this,'+id+',1,"is_best"); src="/style/admin/images/no.gif"/>');
                 } else{
                       alert(data);
                 }
            } else{
                 if (data == 1){ 
                      $(obj).parent().html('<img onclick=EditStatus_best(this,'+id+',0,"is_best") src="/style/admin/images/yes.gif"/>');
                 } else{ 
                      alert(data);
                }
            }
            })
            }
            
            //更改is_news状态
            function EditStatus_news(obj, id, value,is_v){
            $.post("/admin/types/ExitStatus", {"id":id, "_token":"{{csrf_token()}}", "_method":"post", [is_v]:value}, function(data){ 
            if (value == 0){
                 if (data == 1){ 
                       $(obj).parent().html('<img onclick=EditStatus_news(this,'+id+',1,"is_news"); src="/style/admin/images/no.gif"/>');
                 } else{
                       alert(data);
                 }
            } else{
                 if (data == 1){ 
                      $(obj).parent().html('<img onclick=EditStatus_news(this,'+id+',0,"is_news") src="/style/admin/images/yes.gif"/>');
                 } else{ 
                      alert(data);
                }
            }
            })
            }
            
            //更改is_host状态
            function EditStatus_host(obj, id, value,is_v){
            $.post("/admin/types/ExitStatus", {"id":id, "_token":"{{csrf_token()}}", "_method":"post", [is_v]:value}, function(data){ 
            if (value == 0){
                 if (data == 1){ 
                       $(obj).parent().html('<img onclick=EditStatus_host(this,'+id+',1,"is_host"); src="/style/admin/images/no.gif"/>');
                 } else{
                       alert(data);
                 }
            } else{
                 if (data == 1){ 
                      $(obj).parent().html('<img onclick=EditStatus_host(this,'+id+',0,"is_host") src="/style/admin/images/yes.gif"/>');
                 } else{ 
                      alert(data);
                }
            }
            })
            }
            


            //ajax批量删除
            function all_Del(){
            var ids = ""
                    $(".ckb").each(function(){
            if ($(this).is(':checked')){
            ids += "," + $(this).val(); //把要删除的id拼接成字符串
            }
            })
                    ids = ids.substring(1); // 对id进行处理，去除第一个逗号 
            if (ids.length == 0){
            alert("请选择要删除的分类");
            } else{
            if (confirm("确定删除？删除后将无法恢复。")){
            $.post("/admin/types/all_del", {"ids":ids, "_token":"{{csrf_token()}}", "_method":"post"}, function(data){
            if (data == 1){
            window.location.reload();
            } else{
            alert(data);
            }
            })
            }
            }
            }
            //全选或者全取消 
            function SelectAll(){
            $("#del").is(':checked')?$(".ckb").prop("checked", true):$(".ckb").prop("checked", false);
            }
            function del(id){
            $.post("/admin/types/" + id, {"_token":"{{csrf_token()}}", "_method":"delete"}, function(data){
            if (data == 1){
            window.location.reload();
            } else{
            alert(data);
            }
            })
            }
        </script>
    </body>
</html>